package com.usermanage.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.dsna.util.images.ValidateCode;

/**
 * Servlet implementation class CheckCodeServlet
 */
@WebServlet("/CheckCodeServlet")
public class CheckCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckCodeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//声明验证码的宽、高、字符个数、干扰线数量
		int width=150;
		int height=50;
		int codeCount=4;
		int lineCount=5;
		//声明验证码对象
		ValidateCode vc=new ValidateCode(width, height, codeCount, lineCount);
		//获取验证码的方法
		String code1=vc.getCode();
		System.out.println("生成的验证码为："+code1);
		
		//获取Session对象
		HttpSession session=request.getSession();
		//将验证码对象存在Session对象中  key-volue，
		session.setAttribute("code", code1);
		
		//将验证码响应给客户端
		vc.write(response.getOutputStream());
		

		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
